# Maintainer: David Runge <dvzrv@archlinux.org>

_name=openAV-Sorcer
pkgname=sorcer
pkgver=1.1.3
pkgrel=4
pkgdesc="A polyphonic wavetable synth LV2 plugin"
arch=(loong64 x86_64)
url="https://github.com/openavproductions/openav-sorcer"
license=(GPL3)
groups=(
  lv2-plugins
  pro-audio
)
depends=(
  cairo
  gcc-libs
  glibc
)
makedepends=(
  boost
  cmake
  lv2
  ntk
)
checkdepends=(lv2lint)
source=(
  $url/archive/release-$pkgver/$pkgname-release-$pkgver.tar.gz
  $pkgname-1.1.3-lv2-1.18.0.patch::https://github.com/openAVproductions/openAV-Sorcer/pull/26/commits/0c06a2f89a44a8e275f0a592c3ac946eff7b7020.patch
  $pkgname-1.1.3-cmake.patch::https://github.com/openAVproductions/openAV-Sorcer/pull/27/commits/d3be525b6b2fd508658b608bbb52d75d9b85a8ca.patch
)
sha512sums=('d03db6b7d62e785c0428636a0d0f77cbbfd6991f994bccb120317a96a9866e978fae66e6dd0c6a6cd2763147f427bb7ba20f01cd06356797042ff42caaa1eab0'
            '45c5392ad897252490ff59d3cd71df1f9f1120926b53f7bba5ece49f08315c5f2d16ca982aaa1ab8e6fe2e6c02b7dae7b79d75d411f3b169b8ab9f1ad63ed570'
            '2d94f6289d5ef1728e8b22ca3dde3a0506dc9a30259499be4b551dbd0af2384009b943ff366033f49bf9087f38d2dde56ea7672249dcf97fc9d6f2bec230a4d4')
b2sums=('917f5595343f62126470c47b2c0e89912437871c9bdbccbbeb72b962a32b9a864506dc0c329e0fa4e7b754a529a2cbd4ac704ea175eb8435bf364c06cf28c9de'
        'f1ccb3fa15701db626d4a0adff569b890512257e32a2ca56731acb075e110010818c573cc3b3f75f1099a95ce7f6e0d2361781c765af3f77b91cd82fbd36f3ee'
        'b99ef8b1509f1e9e191220a653619e0d5dbecfd0e87861ef7c4d660b9ffccb7535c5c9c336e2cbb65d871dd128c70ffe1c316c540dbefd8842d5e1781a2bb088')

prepare() {
  cd $_name-release-$pkgver
  # fixing build with lv2 >= 1.18.0
  patch -Np1 -i ../$pkgname-1.1.3-lv2-1.18.0.patch
  # making sure cmake respects external CFLAGS/CXXFLAGS/LDFLAGS
  patch -Np1 -i ../$pkgname-1.1.3-cmake.patch
}

build() {
  local cmake_options=(
    -B build
    -D CMAKE_INSTALL_PREFIX=/usr
    -D CMAKE_BUILD_TYPE=None
    -S $_name-release-$pkgver
    -W no-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build --verbose
}

check() {
  local lv2lint_options=(
    -Mpack
    # disable most tests because upstream is basically abandonware: https://github.com/openAVproductions/openAV-Sorcer/issues/28
    -t 'Plugin Instantiation'
    -t 'Plugin Symbols'
    -t 'Plugin Version Minor'
    -t 'Plugin Version Micro'
    -t 'Port Atom Port'
    -t 'UI Symbols'
    -t 'UI Idle Interface'
    -t 'UI Show Interface'
    -I $_name-release-$pkgver/$pkgname.lv2
    "http://www.openavproductions.com/sorcer"
  )
  cp -v build/$pkgname.so $_name-release-$pkgver/$pkgname.lv2/
  lv2lint "${lv2lint_options[@]}"

  ctest --test-dir build --output-on-failure
}

package() {
  depends+=(
    ntk libntk.so
  )

  DESTDIR="$pkgdir" cmake --install build
  install -vDm 644 $_name-release-$pkgver/README.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
